<template>
  <div class="my-counter">
    <button type="button" class="btn btn-light" @click="minus(id)">-</button>
    <input
      type="number"
      class="form-control inp"
      v-model.number="num"
    />
    <button type="button" class="btn btn-light" @click="plus(id)">+</button>
  </div>
</template>

<script>
export default {
  props: ['count',"id"],
  data() {
    return {
      num: this.count,
    }
  },
  methods: {
    minus(id) {
      if (this.num > 0) {
        this.num--
        this.$emit('minus',id,this.num)
      }
    },
    plus(id) {
      this.num++
      this.$emit('plus',id,this.num)
    },
  },
}
</script>

<style lang="less" scoped>
.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
</style>
